<template>
  <div class="reportFormPage">
    <!--    <topOperation/>-->
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">土颗粒分析试验检测记录表（筛分法）</div>
        <div class="codeText">
          <tr>JGLQ01004a</tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <div class="table-border">
        <!-- .........................1111111111111111111111111111111......................................................... -->
        <table height="220px" class="top-table" align="center">
          <tbody>
          <tr>
            <td height="30" align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程名称</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcmc }}</span>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">工程部位/用途</span>
            </td>
            <td width="35%" class="text-center">
              <span>{{ form.gongcbwyt }}</span>
            </td>
          </tr>
          <tr>
            <td height="50" align="center">样品信息</td>
            <td class="specimen-border" colspan="3">
              <span>样品名称：</span>
              <span :class="{ 'placeholder': !form.yangpmc }">{{ form.yangpmc }}</span>
              <span>；样品编号：</span>
              <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>

              <span>；样品数量：</span>
              <span :class="{ 'placeholder': !form.yangpsl }">{{ form.yangpsl }}</span>
              <span>；样品状态：</span>
              <span :class="{ 'placeholder': !form.yangpzt }">{{ form.yangpzt }}</span>
              <span>；来样时间：</span>
              <span :class="{ 'placeholder': !form.yangpsj }">{{ form.yangpsj }}</span>
            </td>
          </tr>

          <tr>
            <td height="25" align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验检测日期</span>
            </td>
            <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->
            <td width="35%" class="text-center">
              <el-input v-model="form.shiyjcrq"/>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">试验条件</span>
            </td>
            <td v-if="isPdf" width="35%">
              温度：
              <span style="display: inline-block; width: 10%;">{{ form.shiytjwd }}</span>
              ℃；湿度：
              <span style="display: inline-block; width: 10%;">{{ form.shiytjsd }}</span>%RH
            </td>
            <td v-else width="35%">
              温度：
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100"
                        style="width: 15%"/>
              ℃；湿度：
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100"
                        style="width: 15%"/>
              %RH
            </td>
          </tr>

          <tr>
            <td height="50" align="center" width="15%">
              <span style="width: 90px; display: inline-block">检测依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.jiancyj }}</span>
              <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                        @dblclick.native="showBsJiancyjView" readonly/>
            </td>
            <td align="center" width="15%">
              <span style="width: 90px; display: inline-block">判定依据</span>
            </td>
            <td width="35%">
              <span v-if="isPdf">{{ form.pandyj }}</span>
              <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView"
                        @focus="handleFocus('pandyj')" class="mark"/>
            </td>
          </tr>
          <tr class="bottom-border">
            <td height="50" align="center">
              <div>主要仪器设备</div>
              <div>名称及编号</div>
            </td>
            <td colspan="3">
              <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark"
                        @dblclick.native="showBsInstrumentView" readonly></el-input>
            </td>
          </tr>
          </tbody>
        </table>

        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
          <tr>
            <td colspan="3" class="td3">筛前总土质量（g）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shaiqztzl" @blur="shaiqztzlChange()"
                        @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'"/>
            </td>
            <td colspan="2" class="td2">小于2mm土质量（g）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.xiaoy2mmtzl" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="3" class="td3">小于2mm土占总土质量（%）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.xiaoy2mmtzztzl" disabled/>
            </td>
            <td colspan="2" class="td2">小于2mm取试样质量（g）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.xiaoy2mmqsyzl"
                        @change="xiaoy2mmqsyzlChange()"/>
            </td>
          </tr>
          <tr>
            <td colspan="4" class="td4">粗筛分析</td>
            <td colspan="5" class="td5">细筛分析</td>
          </tr>
          <tr>
            <td colspan="1" class="td1">孔径（mm）</td>
            <td colspan="1" class="td1">累积留筛土质量（g）</td>
            <td colspan="1" class="td1">小于该孔径土质量（g）</td>
            <td colspan="1" class="td1">小于该孔径土质量百分比（%）</td>
            <td colspan="1" class="td1">孔径（mm）</td>
            <td colspan="1" class="td1">累积留筛土质量（g）</td>
            <td colspan="1" class="td1">小于该孔径的土质量（g）</td>
            <td colspan="1" class="td1">小于该孔径土质量百分比（%）</td>
            <td colspan="1" class="td1">占总土质量百分比（%）</td>
          </tr>

          <tr>
            <td colspan="1" class="td1">60</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm60ljlstzl"
                        @change="shaiqztzlChange('shaiqztzl', 'mm60')" @keydown.native="handleKeyDown($event, 1, 0)"
                        :ref="'1_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm60xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm60xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">2.0</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2p0ljlstzl"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2p0xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2p0xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2p0zztzlbfb" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="1" class="td1">40</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm40ljlstzl"
                        @change="shaiqztzlChange('mm60', 'mm40')" @keydown.native="handleKeyDown($event, 2, 0)"
                        :ref="'2_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm40xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm40xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">1.0</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm1ljlstzl" @change="shaiqztzlChange('mm2'
                  , 'mm1', true)" @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm1xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm1xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm1zztzlbfb" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="1" class="td1">20</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm20ljlstzl"
                        @change="shaiqztzlChange('mm40', 'mm20')" @keydown.native="handleKeyDown($event, 3, 0)"
                        :ref="'3_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm20xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm20xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">0.5</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p5ljlstzl"
                        @change="shaiqztzlChange('mm1', 'mm0p5', true)" @keydown.native="handleKeyDown($event, 3, 1)"
                        :ref="'3_1'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p5xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p5xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p5zztzlbfb" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="1" class="td1">10</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm10ljlstzl"
                        @change="shaiqztzlChange('mm20', 'mm10')" @keydown.native="handleKeyDown($event, 4, 0)"
                        :ref="'4_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm10xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm10xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">0.25</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p25ljlstzl"
                        @change="shaiqztzlChange('mm0p5', 'mm0p25', true)" @keydown.native="handleKeyDown($event, 4, 1)"
                        :ref="'4_1'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p25xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p25xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p25zztzlbfb" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="1" class="td1">5</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm5ljlstzl" @change="shaiqztzlChange('mm10'
                  , 'mm5')" @keydown.native="handleKeyDown($event, 5, 0)" :ref="'5_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm5xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm5xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">0.075</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p075ljlstzl"
                        @change="shaiqztzlChange('mm0p25', 'mm0p075', true)"
                        @keydown.native="handleKeyDown($event, 5, 1)"
                        :ref="'5_1'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p075xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p075xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm0p075zztzlbfb" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="1" class="td1">2</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2ljlstzl" @change="shaiqztzlChange('mm5'
                  , 'mm2')" @keydown.native="handleKeyDown($event, 6, 0)" :ref="'6_0'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2xygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.mm2xygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">底</td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.diljlstzl"
                        @keydown.native="handleKeyDown($event, 6, 1)" :ref="'6_1'"/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.dixygkjtzl" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.dixygkjtzlbfb" disabled/>
            </td>
            <td colspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.dizztzlbfb" disabled/>
            </td>
          </tr>

          <tr>
            <td colspan="1" class="td1">d60（mm）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.d60" disabled/>
            </td>
            <td colspan="1" class="td1">d30（mm）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.d30" disabled/>
            </td>
            <td colspan="1" class="td1">d10（mm）</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.d10" disabled/>
            </td>
          </tr>
          <tr>
            <td colspan="3" class="td3">不均匀系数Cu</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.bujyxs" disabled/>
            </td>
            <td colspan="2" class="td2">曲率系数Cc</td>
            <td colspan="2" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.qulxs" disabled/>
            </td>
          </tr>

          <tr>
            <td colspan="9" height="180" class="echarts-border">
              <table-line-log-more-chart :className="'echarts-border'" :chartData="chartData" :inverse="true"
                                         :isSmooth="true" :xType="'log'" :xMin="'dataMin'" :xMax="'dataMax'"
                                         :minorSplitLine="true"></table-line-log-more-chart>
            </td>
          </tr>

          <tr>
            <td colspan="1" rowspan="2" class="td1">粒组</td>
            <td colspan="1" rowspan="1" class="td1">巨粒组</td>
            <td colspan="4" rowspan="1" class="td4">粗粒组</td>
            <td colspan="1" rowspan="1" class="td1">细粒组</td>
            <td colspan="2" rowspan="1" class="td2">土的鉴别分类和代号</td>
          </tr>
          <tr>
            <td colspan="1" rowspan="1" class="td1">＞60mm</td>
            <td colspan="2" rowspan="1" class="td2">2mm～60mm</td>
            <td colspan="2" rowspan="1" class="td2">0.075～2mm</td>
            <td colspan="1" rowspan="1" class="td1">＜0.075mm</td>
            <td colspan="2" rowspan="2" class="td2">
              <el-input v-model="form.tudjbflhdh" @keydown.native="handleKeyDown($event, 7, 0)" :ref="'7_0'"/>
            </td>
          </tr>
          <tr>
            <td colspan="1" rowspan="1" class="td1">含量（%）</td>
            <td colspan="1" rowspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.ge60hl" disabled/>
            </td>
            <td colspan="2" rowspan="1" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.ge2le60hl" disabled/>
            </td>
            <td colspan="2" rowspan="1" class="td2">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.ge0p75le2hl" disabled/>
            </td>
            <td colspan="1" rowspan="1" class="td1">
              <el-input :type="isPdf ? 'string' : 'number'" v-model="form.le0p75hl" disabled/>
            </td>
          </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')"/>
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
        <tr>
          <td width="10%" align="right">检测：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">记录：</td>
          <td width="15%" align="left"></td>
          <td width="10%" align="right">复核：</td>
          <td align="left" width="15%"></td>
          <td width="10%">日期：</td>
          <td align="left" width="15%">
            <div style="display: inline-block; margin-left: 20px">年</div>
            <div style="display: inline-block; margin-left: 20px">月</div>
            <div style="display: inline-block ;margin-left: 20px">日</div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import {handleFocus, emptyConvert, handleKeyDown} from "@/views/reportForms/utils";
import {getTgTdklfxjlbBsInfo, computeTgTdklfxjlbBsInfo} from "@/api/report_tg/tgTdklfxjlbBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import TableLineLogMoreChart from "@/views/reportForms/components/TableLineLogMoreChart.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";

import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";

export default {
  name: "tdklfxjlb",
  components: {
    BsInstrumentView,
    TableLineLogMoreChart,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      // 表单参数
      form: {},
      chartData: {
        xName: "孔径（mm）",
        yName: "百分比（%）",
        seriesData: [],
        // xData: [],
        // yData: [],
        time: ""
      },
      chartTableArray: [
        {type: "mm60", value: 60, bgType: "60"},
        {type: "mm40", value: 40, bgType: "40"},
        {type: "mm20", value: 20, bgType: "20"},
        {type: "mm10", value: 10, bgType: "10"},
        {type: "mm5", value: 5, bgType: "5"},
        {type: "mm2p0", value: 2, bgType: "2p0"},
        {type: "mm1", value: 1, bgType: "1p0"},
        {type: "mm0p5", value: 0.5, bgType: "0p5"},
        {type: "mm0p25", value: 0.25, bgType: "0p25"},
        {type: "mm0p075", value: 0.075, bgType: "0p075"},
        {type: "di", value: 0}
      ]
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = {...emptyConvert(this.form, newVal)};
    }
  },
  created() {
    // console.log("this.excelId: ", this.excelId);
    this.getInfo();
  },
  methods: {
    // 获取详情
    getInfo() {
      getTgTdklfxjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
        this.calculateInfo();
      });
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setTgBgJiancyj", {jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds});
    },
    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setTgBgZhuyyqsbmcjbh", {zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds});
    },
    // 筛前总土质量改变需要全部重新计算
    shaiqztzlChange() {
      let pType = "shaiqztzl";
      let flag = false;
      for (let index = 0; index < this.chartTableArray.length - 1; index++) {
        const item = this.chartTableArray[index];
        let type = item.type;
        if (item.value == 2) {
          type = "mm2";
        }
        if (item.value < 2) {
          flag = true;
        }
        this.calculateXygkjtzl(pType, type, flag);
        pType = item.type;
      }
      this.calculateInfo();
      // calculateXygkjtzl('mm1', 'mm0p5', true)"
    },
    // 小于2mm取试样质量（g）
    xiaoy2mmqsyzlChange() {
      this.form.mm2p0xygkjtzl = this.form.xiaoy2mmqsyzl;
      this.form.mm2p0xygkjtzlbfb = this.form.xiaoy2mmqsyzl ? "100.0" : "";
      this.shaiqztzlChange();
    },
    // 计算小于该孔径土质量
    calculateXygkjtzl(pType, type, isCalculateZztzlbfb) {
      const pCount = pType == "shaiqztzl" ? this.form["shaiqztzl"] : this.form[pType + "xygkjtzl"];
      const count = this.form[type + "ljlstzl"];
      let xygkjtzl = "";
      if (pCount && count) {
        // 小于该孔径土质量 = 上一级 - 累积留筛土质量
        xygkjtzl = decimal.subtract(pCount, count, 1);
        this.form[type + "xygkjtzl"] = xygkjtzl;
      } else {
        this.form[type + "xygkjtzl"] = "";
      }
      // 大孔径时 小于该孔径土质量百分比 = 小于该孔径土质量/筛前总土质量
      if (!isCalculateZztzlbfb) {
        this.calculateXygkjtzlbfbDK(type);
        // 当孔径为2时 赋值 小于2mm土质量
        if (type == "mm2") {
          this.form.xiaoy2mmtzl = xygkjtzl;
          // this.form.xiaoy2mmqsyzl = xygkjtzl;
          this.form.xiaoy2mmtzztzl = this.form[type + "xygkjtzlbfb"];
          // this.form.mm2p0ljlstzl = this.form.mm2ljlstzl;
          // this.form.mm2p0xygkjtzl = this.form.mm2xygkjtzl;
          // this.form.mm2p0xygkjtzlbfb = "100.0";
          this.form.mm2p0zztzlbfb = this.form.mm2xygkjtzlbfb;
        }
      } else {
        // 小孔径时 小于该孔径土质量百分比 = 小于该孔径土质量/小于2mm土质量
        this.calculateXygkjtzlbfbXK(type);
        // 计算占总土质量百分比
        this.calculateZztzlbfb(type);
      }


    },
    // 计算小于该孔径土质量百分比 - 大孔
    calculateXygkjtzlbfbDK(type) {
      const sum = this.form["shaiqztzl"];
      const count = this.form[type + "xygkjtzl"];
      if (!sum || !count) {
        this.form[type + "xygkjtzlbfb"] = "";
        // this.calculateInfo();
        return;
      }
      // 小于该孔径土质量百分比 = count*100/sum
      const xygkjtzlbfb = decimal.divide(decimal.multiply(count, 100), sum, 1);
      this.form[type + "xygkjtzlbfb"] = xygkjtzlbfb;
      // this.calculateInfo();
    },
    // 计算小于该孔径土质量百分比 - 小孔
    calculateXygkjtzlbfbXK(type) {
      const sum = this.form["xiaoy2mmqsyzl"];
      const count = this.form[type + "xygkjtzl"];
      if (!sum || !count) {
        this.form[type + "xygkjtzlbfb"] = "";
        return;
      }
      // 小于该孔径土质量百分比 = count*100/sum
      const xygkjtzlbfb = decimal.divide(decimal.multiply(count, 100), sum, 1);
      this.form[type + "xygkjtzlbfb"] = xygkjtzlbfb;
    },
    // 计算占总土质量百分比
    calculateZztzlbfb(type) {
      // =(N15*L16)/100
      const N15 = this.form["xiaoy2mmtzztzl"]; // 小于2mm土占总土质量
      const L16 = this.form[type + "xygkjtzlbfb"]; // xx小于该孔径土质量百分比
      if (!N15 || !L16) {
        this.form[type + "zztzlbfb"] = "";
        // this.calculateInfo();
        return;
      }
      // 占总土质量百分比 = 累积留筛土质量*100/筛前总土质量
      const zztzlbfb = decimal.divide(decimal.multiply(N15, L16), 100, 1);
      this.form[type + "zztzlbfb"] = zztzlbfb;
      // this.calculateInfo();
    },

    // 计算土颗粒分析记录
    calculateInfo() {
      // let flg = false;
      // for (let index = 0; index < this.chartTableArray.length - 1; index++) {
      //   const item = this.chartTableArray[index];
      //   const number = item.value > 2 ? this.form[item.type + "xygkjtzlbfb"] : this.form[item.type + "zztzlbfb"];
      //   if (!number) {
      //     flg = true;
      //     break;
      //   }
      // }
      // if (flg) {
      //   return;
      // }
      this.form.chartData = undefined;
      computeTgTdklfxjlbBsInfo(this.form).then((response) => {
        // console.log("response: ", response.data);
        this.form = response.data;
        this.setEcharts();
        this.setBg();
      });
    },
    // 拼接图表数据
    setEcharts() {
      this.chartData.xMax = undefined;
      this.chartData.xMin = undefined;
      this.chartData.yMax = undefined;
      this.chartData.yMin = undefined;
      if (!this.form.chartData || this.form.chartData.length <= 0) {
        this.chartData.seriesData = [];
        return;
      }
      let data1 = [];
      let data2 = [];
      let data3 = [];
      this.form.chartData.forEach((item) => {
        switch (item.flag) {
          case "100":
            data1.push(item.point);
            break;
          case "010":
            data2.push(item.point);
            break;
          case "011":
            data3.push(item.point);
            break;
        }
      });
      let markLineData = [];
      data3.forEach((item) => {
        markLineData.push([
          {
            coord: [60, item[1]]
          },
          {
            coord: [item[0], item[1]]
          }
        ]);
        markLineData.push([
          {
            coord: [item[0], 0]
          },
          {
            coord: [item[0], item[1]]
          }
        ]);
      });
      const chart1 = {
        data: data1,
        connectNulls: true,
        smooth: true,
        symbol: "none",
        type: "line",
        markLine: {
          symbolSize: [1],
          label: {show: false},
          silent: true,
          data: markLineData
        }
      };
      const labelData = data3.map((item) => {
        return {
          value: item,
          label: {
            show: true,
            formatter: JSON.stringify(item),
            position: "top"
          },
          itemStyle: {}
        };
      });
      const chart2 = {
        type: "scatter",
        symbolSize: 4,
        data: [...data2, ...labelData]
      };
      this.chartData.seriesData = [chart1, chart2];
    },
    // 给报告赋值
    setBg() {
      let info = {};
      for (let index = 0; index < this.chartTableArray.length - 1; index++) {
        const item = this.chartTableArray[index];
        info["xiaoygkjzlbfs" + item.bgType] = this.form[item.type + "xygkjtzlbfb"];
        if (item.value <= 2) {
          info["zhanztzlbfb" + item.bgType] = this.form[item.type + "zztzlbfb"];
        }
      }
      info["bujyxs"] = this.form.bujyxs;
      info["qulxs"] = this.form.qulxs;
      info["tuydmjdh"] = this.form.tudjbflhdh;
      Bus.$emit("setTgBgShaiff", info);
    },
    submitForm() {
      return this.form;
    },
    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [0, 0, 1, 1, 1, 1, 1, 0]; // 每一行最多有多少可聚焦输入框（从0开始）
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped>
.td1 {
  width: calc(100% / 9 * 1);
}

.td2 {
  width: calc(100% / 9 * 2);
}

.td3 {
  width: calc(100% / 9 * 3);
}

.td4 {
  width: calc(100% / 9 * 4);
}

.td5 {
  width: calc(100% / 9 * 5);
}

.echarts-border {
  height: 176px;
  width: calc(210mm - 40mm - 8px);
  padding: 2px !important;
  background-color: #ffffff !important;
}
</style>
